package com.edu.service.blog.impl;

import com.edu.entity.blog.Article;
import com.edu.entity.chat.Page;
import com.edu.mapper.blog.ArticleMapper;
import com.edu.service.blog.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: LuckyBear
 * @date: 2018-10-29 20:16
 * @description:
 */
@Service
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    private ArticleMapper articleMapper;

    //模糊查询博客
    @Override
    public List<Article> findBlogByName(String articletitle) {
        return articleMapper.findBlogByName("%"+articletitle+"%");
    }

    //按评论数显示博客列表
    @Override
    public List<Article> listBlogByComment(Page page) {
        return articleMapper.listBlogByComment(page);
    }

    //按发布时间排序显示博客列表
    @Override
    public List<Article> listBlogByTime(Page page) {
        return articleMapper.listBlogByTime(page);
    }

    //按点赞次数排序显示博客列表
    @Override
    public List<Article> listBlogByLike(Page page) {
        return articleMapper.listBlogByLike(page);
    }

    @Override
    public List<Article> myBlog(int id) {
        return articleMapper.myBlog(id);
    }

    //分页
    @Override
    public int getTotal(int pageCount) {
        Integer total = articleMapper.getTotal();
        return (total - 1)/ pageCount + 1;
    }

    //上传博客
    @Override
    public Integer createBlog(Article article) {
        return  articleMapper.createBlog(article);
    }

    //根据博客id获取博客内容
    @Override
    public Article findBlogById(int id) {
        return articleMapper.findBlogById(id);
    }

    @Override
    public List<Article> pageList() {
        return articleMapper.pageList();
    }
}
